home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Sessions / Completions / Completions Source / Files / FileOutStream.cp < prev    next >
Encoding:
Text File  |  1998-06-17  |  2.2 KB  |  133 lines  |  [TEXT/CWIE]

  1. // FileOutStream.cp
  2.  
  3. #ifndef FileOutStream_h
  4. #include "FileOutStream.h"
  5. #endif
  6. #ifndef ConstData_h
  7. #include "ConstData.h"
  8. #endif
  9. #ifndef FileWritingPath_h
  10. #include "FileWritingPath.h"
  11. #endif
  12. #ifndef __DEVICES__
  13. #include <Devices.h>
  14. #endif
  15.  
  16. FileOutStream::FileOutStream()
  17.   {
  18.     ioParam.ioPosMode = fsFromStart;
  19.   }
  20.  
  21. Task *FileOutStream::NonblockingWrite( ConstData buffer )
  22.   {
  23.     return BlockingWrite( buffer );
  24.   }
  25.  
  26. Task *FileOutStream::BlockingWrite( ConstData buffer )
  27.   {
  28.     Assert( !Running() );
  29.     
  30.     ioParam.ioBuffer = reinterpret_cast<Ptr>(
  31.                                 const_cast<uint8 *>( buffer.Start() ) );
  32.     ioParam.ioReqCount = buffer.Length();
  33.     flushing = false;
  34.     
  35.     return this;
  36.   }
  37.  
  38. Task *FileOutStream::FlushingTask()
  39.   {
  40.     flushing = true;
  41.     return this;
  42.   }
  43.  
  44. void FileOutStream::Launch()
  45.   {
  46.     Assert( !Running() );
  47.     
  48.     if ( flushing )
  49.         PBFlushFileAsync( this );
  50.      else
  51.         PBWriteAsync( this );
  52.   }
  53.  
  54. void FileOutStream::Kill()
  55.   {
  56.   }
  57.  
  58. void FileOutStream::AtCompletion()
  59.   {
  60.     Assert( !Running() );
  61.  
  62.     if ( !flushing )
  63.         ReportWrite( ioParam.ioActCount );
  64.     
  65.     if ( ioParam.ioResult != noErr )
  66.         ReportFailure();
  67.   }
  68.         
  69. void FileOutStream::SetFile( const FileWritingPath& path,
  70.                                       uint32 position )
  71.   {
  72.     Assert( !Running() );
  73.     Assert( path.IsOpen() );
  74.     
  75.     ioParam.ioRefNum = path.RefNum();
  76.     ioParam.ioPosOffset = position;
  77.     Reset();
  78.   }
  79.  
  80. void FileOutStream::ClearFile()
  81.   {
  82.     Assert( !Running() );
  83.     ioParam.ioRefNum = 0;
  84.     Reset();
  85.   }
  86.  
  87. uint32 FileOutStream::Position() const
  88.   {
  89.     Assert( !Running() );
  90.     Assert( HasFile() );
  91.     return ioParam.ioPosOffset;
  92.   }
  93.         
  94. void FileOutStream::SetPosition( uint32 p )
  95.   {
  96.     Assert( !Running() );
  97.     Assert( HasFile() );
  98.     ioParam.ioPosOffset = p;
  99.     Reset();
  100.   }
  101.         
  102. void FileOutStream::SuggestCaching()
  103.   {
  104.     Assert( !Running() );
  105.     ioParam.ioPosMode |= cacheBit;
  106.     ioParam.ioPosMode &= ~noCacheBit;
  107.   }
  108.         
  109. void FileOutStream::SuggestNoCaching()
  110.   {
  111.     Assert( !Running() );
  112.     ioParam.ioPosMode |= noCacheBit;
  113.     ioParam.ioPosMode &= ~cacheBit;
  114.   }
  115.         
  116. void FileOutStream::ClearCachingSuggestion()
  117.   {
  118.     Assert( !Running() );
  119.     ioParam.ioPosMode &= ~( noCacheBit | cacheBit );
  120.   }
  121.         
  122. void FileOutStream::VerifyWrites()
  123.   {
  124.     Assert( !Running() );
  125.     ioParam.ioPosMode |= rdVerify;
  126.   }
  127.         
  128. void FileOutStream::DontVerifyWrites()
  129.   {
  130.     Assert( !Running() );
  131.     ioParam.ioPosMode &= ~rdVerify;
  132.   }
  133.